﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Aulac.Global.Enums; using Aulac.Global.Data; using Aulac.Global.Common; using Aulac.Global.Xml;
using Aulac.Rsc.Ems; using Aulac.Rsc.Ems.Tags;
using System.Data;
using Aulac.Srv.Db.Provider; using Aulac.Srv.Db.Connect;
using Aulac.Srv.Db.Data.Catalogs;


namespace Aulac.Srv.Db.Data.Ems.Items.ItemType
{
    public class ClsObjTypes: DbDataCatalogs
    {
        private List<string> mList = new List<string>(new string[] { tagItems.Obj.ObjTypeID, tagItems.Obj.ObjTypeEnum, tagItems.Obj.ObjTypeName, tagItems.Obj.TableContain, tagItems.Obj.ObjTypeGrpID });

        public ClsObjTypes(IDbAulacConnect pDb)
            : base(pDb, TableNames.Dm_ObjectTypes, tagItems.Obj.ObjTypeID,
            new string[] { tagItems.Obj.ObjTypeEnum, tagItems.Obj.ObjTypeName }
            )
        {
            
        }
        protected override void OnGetListItem(ref DataTable pDataReturn, XmlDataDocument xmlParams)
        {
            try
            {
                string pCollection = XmlProcess.GetValueParam(xmlParams, tagItems.Common.CollectionFields);
                string sGrpObjType = XmlProcess.GetValueParam(xmlParams, tagItems.Obj.ObjTypeGrpID);
                sqlQuery = string.Format("SELECT {0} FROM {1} ", StringHelper.ConvertArrayToString(", ", mList.ToArray()), TableNames.Dm_ObjectTypes);
                sqlQuery += string.Format(" WHERE (N'{0}' = '' OR {1} IN ({2}))", pCollection, tagItems.Obj.ObjTypeID, (isEmpty(pCollection) ? "0" : pCollection));
                sqlQuery += string.Format(" AND (? IS NULL OR {0} = ?)", tagItems.Obj.ObjTypeGrpID);
                DbDataProvider.ExecuteReaderDataToTable(mDbCmd, sqlQuery, ref pDataReturn, sGrpObjType, sGrpObjType);
            }
            catch (DataException ex)
            {
                throw ex;
            }
        }
    }
}
